<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$lotto_id = intval($_GET['id']);
$conf = new Config();
$startbet = $conf->get("startbet");
$stopbet = $conf->get("waitbet");
$prot_start = $conf->get("protect_start");
if (!isset($_SESSION['bsaystartmod']))
{
    $_SESSION['bsaystartmod'] = 0;
}
$saystartmod = $_SESSION['bsaystartmod'];
if (!isset($_SESSION['bsaywaitmod']))
{
    $_SESSION['bsaywaitmod'] = 0;
}
$saystopmod = $_SESSION['bsaywaitmod'];
if ($stopbet <= date("Hi") && !$saystopmod)
{
    $saystopmod = 1;
    $_SESSION['bsaywaitmod'] = $saystopmod;
    echo "-1";
    exit();
}
$stopmode = $prot_start == 0 ? 1 : $saystopmod;
if ($saystopmod == 0 && $prot_start != $saystartmod)
{
    $saystartmod = $prot_start;
    $_SESSION['bsaystartmod'] = $saystartmod;
    $stopmode = $saystartmod;
    echo "-1";
    exit();
}
$percent = 1;
$amounts = array();
$counts = array();
$totalamount = array();
$totalcount = array();
$betids = array(15, 16, 17, 23);
$total_win = array();
$ary = array();
foreach ($betids as $betid)
{
    $i = 1;
    while ($i < 7)
    {
        $total_win[$betid][$i] = 0;
        ++$i;
    }
    $ary[$betid] = array();
}
$i = 1;
while ($i < 7)
{
    if (!isset($ary[15][$i]))
    {
        $ary[15][$i] = array();
    }
    if (!isset($ary[16][$i]))
    {
        $ary[16][$i] = array();
    }
    if (!isset($ary[17][$i]))
    {
        $ary[17][$i] = array();
    }
    if (!isset($ary[23][$i]))
    {
        $ary[23][$i] = array();
    }
    $ary[15][$i][1] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[15][$i][2] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[16][$i][3] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[16][$i][4] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[17][$i][5] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[17][$i][6] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[17][$i][7] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[23][$i][8] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    $ary[23][$i][9] = array("rate" => 0, "amount" => 0, "count" => 0, "lost" => 0);
    ++$i;
}
$sql = "select * from bet where lotto_id=" . $lotto_id . " and bettype in (15,16,17,23) and rame in (0,9)";
$theacl = $curruser['acl'];
$userid = $curruser['id'];
$userlist = GetUserList($userid);
if ($userlist == "")
{
    exit("Not Users!");
    exit();
}
$sql .= " and user_id in (" . $userlist . ") order by bettype";
$rs = getdb($sql);
while (!$rs->eof)
{
    $percent = 1;
    $backs = 100;
    if ($theacl == 5)
    {
        $backs = $rs->f['back4'];
        $percent = $rs->f['percent4'];
    }
    else if ($theacl == 4)
    {
        $backs = $rs->f['back3'];
        $percent = $rs->f['percent3'];
    }
    else if ($theacl == 3)
    {
        $backs = $rs->f['back2'];
        $percent = $rs->f['percent2'];
    }
    else
    {
        $backs = $rs->f['back1'];
        $percent = $rs->f['mpercent'];
    }
    if (0 < $percent)
    {
        $percent /= 100;
    }
    $tmp = $percent * $rs->f['amount'];
    $num = explode(" ", $rs->f['numbers']);
    $ary[$rs->f['bettype']][$num[0]][$num[1]]['amount'] += $tmp;
    ++$ary[$rs->f['bettype']][$num[0]][$num[1]]['count'];
    $ary[$rs->f['bettype']][$num[0]][$num[1]]['lost'] += $tmp * $rs->f['rate'];
    $total_win[$rs->f['bettype']][$num[0]] += $tmp * ( $backs / 100 );
    $rs->movenext();
}
$rs->close();
if (2 < $theacl)
{
    $sql = "select * from bet2 where lotto_id=" . $lotto_id . " and uperid" . $theacl . "=" . $userid . " and bettype in (15,16,17,23) and rame in (0,9) order by bettype";
    $rs = getdb($sql);
    while (!$rs->eof)
    {
        $percent = 1;
        $backs = 100;
        if ($theacl == 5)
        {
            $backs = $rs->f['back5'];
            $percent = $rs->f['percent5'];
        }
        else if ($theacl == 4)
        {
            $backs = $rs->f['back4'];
            $percent = $rs->f['percent4'];
        }
        else if ($theacl == 3)
        {
            $backs = $rs->f['back3'];
            $percent = $rs->f['percent3'];
        }
        if (0 < $percent)
        {
            $percent /= 100;
        }
        if ($rs->f['prev_id'] == 0)
        {
            $percent = 0;
        }
        $tmp = $percent * $rs->f['amount'];
        $num = explode(" ", $rs->f['numbers']);
        $ary[$rs->f['bettype']][$num[0]][$num[1]]['amount'] += $tmp;
        ++$ary[$rs->f['bettype']][$num[0]][$num[1]]['count'];
        $ary[$rs->f['bettype']][$num[0]][$num[1]]['lost'] += $tmp * $rs->f['rate'];
        $total_win[$rs->f['bettype']][$num[0]] += $tmp * ( $backs / 100 );
        $rs->movenext();
    }
    $rs->close();
}
$sql = "select * from bet2 where lotto_id=" . $lotto_id . " and user_id=" . $userid . " and bettype in (15,16,17,23) and rame in (0,9) order by bettype";
$rs = getdb($sql);
while (!$rs->eof)
{
    $backs = 100;
    if ($theacl == 5)
    {
        $backs = $rs->f['back5'];
    }
    else
    {
        if ($theacl == 4)
        {
            $backs = $rs->f['back4'];
        }
        if ($theacl == 3)
        {
            $backs = $rs->f['back3'];
        }
        else if ($theacl == 2)
        {
            $backs = $rs->f['back2'];
        }
    }
    $tmp = $rs->f['amount'];
    $num = explode(" ", $rs->f['numbers']);
    $ary[$rs->f['bettype']][$num[0]][$num[1]]['amount'] -= $tmp;
    $ary[$rs->f['bettype']][$num[0]][$num[1]]['lost'] -= $tmp * $rs->f['rate'];
    $total_win[$rs->f['bettype']][$num[0]] -= $tmp * ( $backs / 100 );
    $rs->movenext();
}
$rs->close();
$rs = getdb("select * from rate15a where lotto_id=" . $lotto_id);
if ($rs->eof)
{
    exit("Error ID!");
}
$rss = get_srates_data($userid, $lotto_id, 23);
if ($rss->eof)
{
    exit("Error ID!");
}
$i = 1;
while ($i < 7)
{
    $ary[15][$i][1]['rate'] = $rs->f["r15_" . $i . "_1"] - $rss->f["r15_" . $i . "_1"] - 0;
    $ary[15][$i][2]['rate'] = $rs->f["r15_" . $i . "_2"] - $rss->f["r15_" . $i . "_2"] - 0;
    $ary[16][$i][3]['rate'] = $rs->f["r15_" . $i . "_3"] - $rss->f["r15_" . $i . "_3"] - 0;
    $ary[16][$i][4]['rate'] = $rs->f["r15_" . $i . "_4"] - $rss->f["r15_" . $i . "_4"] - 0;
    $ary[17][$i][5]['rate'] = $rs->f["r15_" . $i . "_5"] - $rss->f["r15_" . $i . "_5"] - 0;
    $ary[17][$i][6]['rate'] = $rs->f["r15_" . $i . "_6"] - $rss->f["r15_" . $i . "_6"] - 0;
    $ary[17][$i][7]['rate'] = $rs->f["r15_" . $i . "_7"] - $rss->f["r15_" . $i . "_7"] - 0;
    $ary[23][$i][8]['rate'] = $rs->f["r15_" . $i . "_8"] - $rss->f["r15_" . $i . "_8"] - 0;
    $ary[23][$i][9]['rate'] = $rs->f["r15_" . $i . "_9"] - $rss->f["r15_" . $i . "_9"] - 0;
    ++$i;
}
$rs->close();
$i = 1;
while ($i < 7)
{
    echo $total_win[15][$i];
    echo "," . $ary[15][$i][1]['rate'] . "@" . $ary[15][$i][1]['count'] . "@" . $ary[15][$i][1]['amount'];
    echo "@" . $ary[15][$i][1]['lost'];
    echo "," . $ary[15][$i][2]['rate'] . "@" . $ary[15][$i][2]['count'] . "@" . $ary[15][$i][2]['amount'];
    echo "@" . $ary[15][$i][2]['lost'];
    echo "\n";
    echo $total_win[16][$i];
    echo "," . $ary[16][$i][3]['rate'] . "@" . $ary[16][$i][3]['count'] . "@" . $ary[16][$i][3]['amount'];
    echo "@" . $ary[16][$i][3]['lost'];
    echo "," . $ary[16][$i][4]['rate'] . "@" . $ary[16][$i][4]['count'] . "@" . $ary[16][$i][4]['amount'];
    echo "@" . $ary[16][$i][4]['lost'];
    echo "\n";
    echo $total_win[17][$i];
    echo "," . $ary[17][$i][5]['rate'] . "@" . $ary[17][$i][5]['count'] . "@" . $ary[17][$i][5]['amount'];
    echo "@" . $ary[17][$i][5]['lost'];
    echo "," . $ary[17][$i][6]['rate'] . "@" . $ary[17][$i][6]['count'] . "@" . $ary[17][$i][6]['amount'];
    echo "@" . $ary[17][$i][6]['lost'];
    echo "," . $ary[17][$i][7]['rate'] . "@" . $ary[17][$i][7]['count'] . "@" . $ary[17][$i][7]['amount'];
    echo "@" . $ary[17][$i][7]['lost'];
    echo "\n";
    echo $total_win[23][$i];
    echo "," . $ary[23][$i][8]['rate'] . "@" . $ary[23][$i][8]['count'] . "@" . $ary[23][$i][8]['amount'];
    echo "@" . $ary[23][$i][8]['lost'];
    echo "," . $ary[23][$i][9]['rate'] . "@" . $ary[23][$i][9]['count'] . "@" . $ary[23][$i][9]['amount'];
    echo "@" . $ary[23][$i][9]['lost'];
    echo "\n";
    ++$i;
}
include( "class_6h/class.menu.php" );
$fieldArr = array("lotto_id" => $lotto_id, "split_id" => 1);
$onlineMenu = new menu_6h(12, $fieldArr);
echo $onlineMenu->getMenuAmu();
echo "\n";
exit();